package de.dhbw.karlsruhe.picsim.model.timer;

import org.jetbrains.annotations.NotNull;

import java.util.Collection;
import java.util.concurrent.CopyOnWriteArraySet;

/**
 * Created by IntelliJ IDEA.
 * User: goesen
 * Date: Apr 28, 2010
 * Time: 7:25:19 PM
 */
abstract class TimerSupport implements ObservableTimer {
    private final Collection<TimeoutListener> listeners = new CopyOnWriteArraySet<TimeoutListener>();

    @Override
    public final void addTimeoutListener(@NotNull final TimeoutListener listener) {
        listeners.add(listener);
    }

    @Override
    public final void removeTimeoutListener(@NotNull final TimeoutListener listener) {
        listeners.remove(listener);
    }

    final void fireTimeout() {
        for (final TimeoutListener listener : listeners) {
            listener.timeoutOccurred();
        }
    }
}
